package net.huashitong.ssydt.provider.exam.service;


import net.huashitong.ssydt.exam.entity.SsExamPaperRecord;
import net.huashitong.ssydt.provider.exam.mapper.SsExamPaperRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2017.09.04
 */
@Service
@Transactional
public class SsExamPaperRecordServiceImpl implements SsExamPaperRecordService {

    private SsExamPaperRecordMapper mapper;

    @Autowired
    public SsExamPaperRecordServiceImpl(SsExamPaperRecordMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public SsExamPaperRecord getNotHistoryByUserIdAndPaperId(String userId, Long paperId) {
        SsExamPaperRecord record = new SsExamPaperRecord();
        record.setUserId(userId);
        record.setPaperId(paperId);
        return mapper.getNotHistoryByUserIdAndPaperId(record);
    }

    @Override
    public void updateByPrimaryKey(SsExamPaperRecord ssExamPaperRecord) {
        mapper.updateByPrimaryKey(ssExamPaperRecord);
    }

    @Override
    public void insert(SsExamPaperRecord ssExamPaperRecord) {
        mapper.insert(ssExamPaperRecord);
    }

    @Override
    public SsExamPaperRecord getById(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public int countSubmittedByPaperId(Long paperId) {
        return mapper.countSubmittedByPaperId(paperId);
    }

    @Override
    public int countSubmittedByPaperIdWithLessOrEqualsCorrectNumber(Long paperId, Integer correctNumber) {
        SsExamPaperRecord record = new SsExamPaperRecord();
        record.setPaperId(paperId);
        record.setCorrectNumber(correctNumber);
        return mapper.countSubmittedByPaperIdWithLessOrEqualsCorrectNumber(record);
    }
}
